<template>
  <!--规格显示选择-->
  <div class="sku-box">
    <div class="sku-top-box">
      <div class="sku-tt flex">
        <div class="pro-sku-img">
          <img :src="skuobj.main_img">
        </div>
        <div class="pro-sku-tit">
          <p class="tit">{{skuobj.protit}}</p>
          <p class="price">{{skuobj.exclusiveprice}}</p>
        </div>
      </div>
      <div class="sku-list">
        <skulist :skuobj="skuobj" @getPrice="getSelectPrice" @skuid="getSkuId" @statusString="getSelectedstatus" ref="child1"></skulist>
      </div>
      <div class="pro-amount-con">
        <label>购买数量：</label>
        <proinfonumbox @getcount="getcount"></proinfonumbox>
      </div>
    </div>
    <div class="sku-submit" @click="submit()">确认</div>
  </div>
</template>

<script>
// 导入skulist组件
import skulist from "../sku/skuList.vue";
// 导入数量组件
import proinfonumbox from "../../subcomponents/numbox/proinfo_numbox.vue";
export default {
  data() {
    return {
      count: 1 ,//存放商品数量
      selectedskuid:0,
      price:0,//存放选中的商品价格
      childpopVis:false,
      selctedsku:""
    };
  },
  components: {
    skulist,
    proinfonumbox
  },
  created() {
  },
  methods: {
    getSelectPrice(price) {
      if(price==="库存不足"){
         this.skuobj.exclusiveprice = price;
      }else{
        this.skuobj.exclusiveprice = "￥"+price+"元";
        this.price=price
      }
      
    },
    getSkuId(skuid) {
      this.selectedskuid= skuid;

    },
    getcount(count) {
      this.count = count;
    },
    getSelectedstatus(selctedsku) {
      this.selctedsku = selctedsku;
    },
    //购物车
    addcart() {
      var goodsinfo = {
        id: this.ids,
        count: this.count,
        zs_price: this.price,
        skuid: this.selectedskuid,
        selectstatus:this.selctedsku,
        selected: true
      };
      console.log(goodsinfo)
      this.$store.commit("addToCar", goodsinfo);
    },
    //提交
    submit() {
      if (this.type) {
      var goodsinfo = {
        id: this.ids,
        count: this.count,
        zs_price: this.price,
        skuid: this.selectedskuid,
        selectstatus:this.selctedsku,
      };
        console.log("立即购买");
      } else {
        if (this.skuobj.exclusiveprice == "库存不足") {
          console.log("库存不足");
        } else {
          this.addcart();
          this.childpopVis = false;
          this.$emit("getpopupVisible",  this.childpopVis);
          alert("添加成功");
        }
      }
    }
  },
  props: ["skuobj", "type","ids"]
};
</script>

        